package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ClipView06
* */
class ClipView06 @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            color = context.resources.getColor(R.color.color_DC8717)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            mPath.apply {
                reset()
                //Path.FillType.EVEN_ODD---去除两者之间的公共部分，两者之间的非公共部分保留原样，不受两者之间方向影响
                //Path.FillType.INVERSE_EVEN_ODD---保留两者非公共部分和公共部分，两者之间方向互异，不受两者之间方向影响
                fillType = Path.FillType.EVEN_ODD
                //fillType = Path.FillType.INVERSE_EVEN_ODD
                addCircle(
                    -cx * 4 / 8 + cx * 3 / 10,
                    0F,
                    cx * 4 / 8,
                    Path.Direction.CW
                )

                addCircle(
                    cx * 4 / 8 - cx * 3 / 10,
                    0F,
                    cx * 4 / 8,
                    Path.Direction.CCW
                )
            }

            drawPath(mPath, mPaint)
        }
    }
}